package opration;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张宇田
 * Date: 2024-10-14
 * Time: 18:55
 */
public class sendBook implements IOprable{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入你要借阅的图书");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        BookList bookList1 = new BookList();
        int size = bookList1.getSize();
        for (int i = 0; i < size; i++) {
            Book book = bookList.books[i]; // 直接访问传入的bookList的books数组
            if (book.getName().equals(name)) {
                if (book.isBored) {
                    System.out.println("借阅失败哦，该图书已被借走！");
                    return;
                }
                System.out.println("借阅成功");
                book.isBored = true; // 直接修改传入的bookList中的书的isBored状态
                return;
            }
        }
        System.out.println("未找到该图书");
    }
        /*for (int i = 0;i<size;i++){
            Book book = bookList.books[i];
            if (book.getName().equals(name)){
                if (book.isBored == false){
                    System.out.println("借阅成功！");
                    book.isBored = true;
                    return;
                }
                System.out.println("很抱歉，借阅失败！- ！");
            }
        }*/
        /*for (int i =0 ;i<size;i++){

            if(bookList1.books[i].getName().equals(name)){
                //System.out.println("找到了");
                //System.out.println(name + "借阅成功！");
                Book book = bookList1.books[i];
                if(book.isBored == true){
                    System.out.println("借阅失败哦，该图书已被借走！");
                    return;
                }
                System.out.println("借阅成功");
                book.isBored = true;
                return;
            }
        }*/

}
